package chen.huai.jie.spring.xmlconfig.web.controller;

import chen.huai.jie.spring.xmlconfig.mq.activemq.sender.ActiveMqSender;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "ActiveMQ消息发送相关API")
@RestController
@RequestMapping(value = "/activemq/sender", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ActiveMqController extends BaseController {
    @Autowired
    private ActiveMqSender activeMqSender;
    @Autowired(required = false)
    private ActiveMQQueue outActiveMqMessageQueue;
    @Autowired(required = false)
    private ActiveMQTopic outActiveMqMessageTopic;

    @ApiOperation(value = "发送消息到Queue.", notes = "发送消息到Queue")
    @RequestMapping(value = "/queue", method = RequestMethod.GET)
    public boolean outQueue() {
        activeMqSender.sendMessageToQueue(outActiveMqMessageQueue, "ActiveMq queue message.");
        return true;
    }

    @ApiOperation(value = "发送消息到Topic.", notes = "发送消息到Topic")
    @RequestMapping(value = "/topic", method = RequestMethod.GET)
    public boolean outTopic() {
        activeMqSender.sendMessageToTopic(outActiveMqMessageTopic, "ActiveMq topic message.");
        return true;
    }
}
